package com.neuedu.mblog.service;

import com.neuedu.mblog.dao.ChannelDao;
import com.neuedu.mblog.entiry.Channel;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;

/**
 * 项目：vue-ifs
 * 创建时间：  2022-03-11   9:45
 * 作者 :jshand
 * 描述 : s
 */
public class ChannelService {
    ChannelDao channelDao = new ChannelDao();

    public List<Channel> list() throws SQLException {
        String sql = "SELECT   id,   key_ ,  NAME ,   STATUS , thumbnail , weight FROM  mto_channel";
        Object[] params = null;
        List<Channel> list = channelDao.selectList(sql, params);

        return list;
    }


    public boolean save(HttpServletRequest request) throws SQLException {
        Channel channel = new Channel();
        channel.setKey(request.getParameter("key"));
        channel.setName(request.getParameter("name"));
        channel.setThumbnail(request.getParameter("thumbnail"));
        channel.setWeight(Integer.parseInt(request.getParameter("weight")));
        return channelDao.save(channel) >0;
    }


    public Channel queryById(HttpServletRequest request) throws SQLException {
        String id = request.getParameter("id");

        return channelDao.selectById(Integer.parseInt(id));
    }



    public boolean update(HttpServletRequest request) throws SQLException {
        Channel channel = new Channel();
        channel.setId(Integer.parseInt(request.getParameter("id")));
        channel.setKey(request.getParameter("key"));
        channel.setName(request.getParameter("name"));
        channel.setThumbnail(request.getParameter("thumbnail"));
        channel.setWeight(Integer.parseInt(request.getParameter("weight")));
        return channelDao.update(channel) >0;
    }

    public boolean delete(HttpServletRequest request) throws SQLException {
        String id = request.getParameter("id");
        return channelDao.delete(Integer.parseInt(id))>0;
    }
}
